package com.minyifang.wcspf.work.ui.user.presenter;

import com.google.gson.Gson;
import com.minyifang.wcspf.common.base.BasePresenter;
import com.minyifang.wcspf.common.config.network.Constants;
import com.minyifang.wcspf.common.config.network.RetrofitHelper;
import com.minyifang.wcspf.common.config.user.UserManager;
import com.minyifang.wcspf.common.md5.SafeUtils;
import com.minyifang.wcspf.common.utils.LogUtil;
import com.minyifang.wcspf.work.ui.user.model.RefundDetailsBean;
import com.minyifang.wcspf.work.ui.user.view.RefundDetailsView;

import org.json.JSONObject;

import java.util.HashMap;
import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;

/**
 * Created by LuoYaWei on 2018/8/23.
 */
public class RefundDetailsPresenter extends BasePresenter<RefundDetailsView> {
    public void getData(String id) {
        Map<String, Object> map = new HashMap<>();
        map.put("orderId", id);
        JSONObject aesJsonData = Constants.getAESJsonData(map, UserManager.getInstance().getToken());
        RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), aesJsonData.toString());
        addTask(RetrofitHelper.getInstance().getService().getRefundDetails(requestBody), respond -> {
            if (respond.result == 1) {
                LogUtil.e("退款详情:" + SafeUtils.decrypt(respond.data));
                RefundDetailsBean bean = new Gson().fromJson(SafeUtils.decrypt(respond.data),RefundDetailsBean.class);
                getView().showData(bean);
            } else
                getView().showRequestFailed(respond.message);
        });
    }
}
